package top.kaoshanji.r6ch13b;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/5/11 17:43
 */
@Repository // 代码清单-r6ch13b-429页a：使用@Repository注解声明一个DAO
public class ForumDao {

    private JdbcTemplate jdbcTemplate;

    // 代码清单-r6ch13b-02：在DAO类里注入JdbcTemplate
    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void initDb() {

        String sql = " CREATE TABLE t_user3(user_id int primary key, user_name varchar(60)) ";
        jdbcTemplate.execute(sql);

    }

}
